﻿using System;
using System.Collections.Generic;
using Ue.CQRS.Events;
using Ue.CQRS.Samples.DataContracts;
using Ue.CQRS.Samples.Repositories;

namespace Ue.CQRS.Samples.EventHandlers
{
    public class CacheEventHandler : IEventHandler
    {
        private IRepository<BookContract> bookRepository;

        public CacheEventHandler(IRepository<BookContract> bookRepository)
        {
            this.bookRepository = bookRepository;
        }

        [EventHandler]
        public void BookCreateHandle(BookContract bookContract)
        {
            this.bookRepository.AddOrUpdate(bookContract.Id.Value,bookContract);
        }

        [EventHandler]
        public void BookUpdateHandle(BookContract bookContract)
        {
            this.bookRepository[bookContract.Id.Value] = bookContract;
        }
    }
}
